from django.urls import path, include
from rest_framework.routers import DefaultRouter
from rest_framework_nested import routers
from .views import DockerServerViewSet, DockerContainerViewSet, DockerImageViewSet, DockerImageDownloadView, DockerNetworkViewSet, DockerVolumeViewSet, DockerRegistryViewSet

# 创建路由器
router = DefaultRouter()
router.register(r'servers', DockerServerViewSet, basename='docker-servers')
router.register(r'registries', DockerRegistryViewSet, basename='docker-registries')

# 创建嵌套路由器用于容器管理
servers_router = routers.NestedDefaultRouter(router, r'servers', lookup='server')
servers_router.register(r'containers', DockerContainerViewSet, basename='server-containers')
servers_router.register(r'volumes', DockerVolumeViewSet, basename='server-volumes')
servers_router.register(r'images', DockerImageViewSet, basename='server-images')
servers_router.register(r'networks', DockerNetworkViewSet, basename='server-networks')

# URL配置
urlpatterns = [
    path('', include(router.urls)),
    path('', include(servers_router.urls)),
    path('download/<str:filename>/', DockerImageDownloadView.as_view(), name='docker-image-download'),
]

# 应用名称
app_name = 'docker_management'
